import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import ElementUI from "element-ui";
import axios from "axios";

import "element-ui/lib/theme-chalk/index.css";

Vue.use(ElementUI);

//axios.defaults.baseURL = "http://localhost:3000"; //编译前要注释掉测试url
//在./utils/fetch.js文件中同样有此url测试语句，发布后
//Vue.http.options.emulateJSON = true;

Vue.prototype.axios = axios;

Vue.config.productionTip = false;

new Vue({
  router,
  store,
  created() {
    store.dispatch("getuserrole").then(res => {
      const role = res.role;
      store.dispatch("GenerateRoutes", role).then(() => {
        router.addRoutes(store.getters.addRouters);
      });
    });
    store.dispatch("getadminlist");
    store.dispatch("getrolelist");
  },
  render: h => h(App)
}).$mount("#app");
/*
router.beforeEach((to, from, next) => {
  if (store.getters.role.length === 0) {
    store
      .dispatch("getuserrole")
      .then(res => {
        const role = res.role;
        store.dispatch("GenerateRoutes", role).then(() => {
          router.addRoutes(store.getters.addRouters);
          next({ ...to, replace: true });
        });
      })
      .catch(error => {
        console.log(error);
      });
  } else {
    next();
  }
});
*/
